package cn.bdqn.service.course;

import cn.bdqn.dao.course.CourseTagMapper;
import cn.bdqn.pojo.course.CourseTag;
import cn.bdqn.vo.course.CourseTagVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseTagService {
    @Autowired
    private CourseTagMapper courseTagMapper;

    //查询所有标签
    public List<CourseTagVo> selectAllCourseTag(){
        return courseTagMapper.selectAllCourseTag();
    }

    public CourseTag selectCourseTagById(Integer id){
        return courseTagMapper.selectById(id);
    }

    //查询标签总数
    public Long selectCourseTagCount(){return courseTagMapper.selectCount(null);}
    //查询一级标签
    public List<CourseTag> selectCourseTageLevel1(){return courseTagMapper.selectList(new QueryWrapper<CourseTag>().isNull("course_tag_parent_id"));}
    //查询一、二级标签
    public List<CourseTagVo> selectParentTag(){return courseTagMapper.selectParentTag();}
    //根据标签名称查询标签
    public List<CourseTag> selectCourseTagByName(String courseTagName){
        return courseTagMapper.selectList(new QueryWrapper<CourseTag>().like("course_tag_name",courseTagName));
    }
    //根据一级标签id,二、三级标签状态、三级标签名称查询课程标签
    public List<CourseTagVo> selectCourseTagByNameAndStatusAndId(Integer[] tagIds,Integer tagStatus,String tagName){
        return courseTagMapper.selectCourseTagByNameAndStatusAndId(tagName, tagStatus, tagIds);
    }
    //根据课程id查询标签
    public List<CourseTag> selectCourseTagByCourseId(Integer courseId){
        return courseTagMapper.selectCourseTagByCourseId(courseId);
    }
    //添加标签
    public Integer insertCourseTag(CourseTag courseTag){
        return courseTagMapper.insert(courseTag);
    }
    //根据标签id修改标签信息
    public Integer updateCourseById(CourseTag courseTag){
        return courseTagMapper.updateById(courseTag);
    }
    //根据标签id删除标签
    public Integer deleteCourseTagById(Integer id){
        return courseTagMapper.delete(new QueryWrapper<CourseTag>().eq("course_tag_id",id));
    }
    //根据标签id修改标签状态
    public Integer updateCourseTagStatusById(Integer id,Integer status){
        return courseTagMapper.update(null,new UpdateWrapper<CourseTag>().eq("course_tag_id",id).set("course_tag_status",status));
    }

    //根据标签id修改标签名称
    public Integer updateCourseTagNameById(Integer id,String tagName){
        return courseTagMapper.update(null,new UpdateWrapper<CourseTag>().eq("course_tag_id",id).set("course_tag_name",tagName));
    }
    //根据标签id修改父级标签
    public Integer updateCourseTagParentIdById(Integer id,String newParentId){
        return courseTagMapper.update(null,new UpdateWrapper<CourseTag>().eq("course_tag_id",id).set("course_tag_parent_id",newParentId));
    }

}
